<template>
	<view class="notice-system">
		<gyd-navbar back-color="#fff" :title="title"></gyd-navbar>

		<u-cell-group v-if="list.length > 0">
			<u-cell v-for="(item,index) in list" :key="index" :title="item.title" @click="detail(item)">
				<template #icon>
					<up-icon size="22" name="bell-fill" v-if="item.has_read == 0"></up-icon>
					<up-icon size="22" name="bell" v-else></up-icon>
				</template>
				<template #value v-if="item.has_read == 0">
					<u-badge value="未读"></u-badge>
				</template>
			</u-cell>
		</u-cell-group>

		<view v-if="list.length <= 0" style="text-align: center;margin-top: 30rpx;">
			<text>
				暂无数据~
			</text>
		</view>
	</view>
</template>

<script setup>
	import request from '@/utils/request';
	import cache from '@/utils/cache';
	import util from '@/utils/util';
	import {
		ref,
		reactive,
		toRefs,
		inject,
	} from 'vue';
	import {
		onLoad,
		onShow,
		onReady,
		onPullDownRefresh,
		onReachBottom,
	} from '@dcloudio/uni-app';

	const state = reactive({
		title: '系统消息',
		themeColor: cache.get('themeColor'),
		imgHost: util.requestUrl(),
		isMore: true,
		list: [],
		noread: {
			color: "red"
		}
	});

	//在页面所有元素加载完成后执行（只执行一次）
	onLoad((opt) => {
		console.log('onLoad');
		if (opt.hasOwnProperty('id')) {
			console.log('传递参数', opt.id);
		}
		initData();
	});

	//在页面由不可见变为可见时执行（只要页面显示都会执行）
	onShow(() => {
		console.log('onShow');
	})

	//在页面解析完成之后执行
	onReady(() => {
		console.log('onReady');
	})

	onPullDownRefresh(() => {
		console.log('下拉刷新');
		setTimeout(() => {
			uni.stopPullDownRefresh();
		}, 1000);
	})

	onReachBottom(() => {
		console.log('触底加载更多');
	})

	function initData() {
		state.list = [{
			id: 1,
			title: '系统消息一',
			has_read: 1,
			image: state.imgHost + '/uploads/202508/295674320250811.png',
			create_time: '2025-09-05 16:09:41'
		}, {
			id: 2,
			title: '系统消息二',
			has_read: 0,
			image: state.imgHost + '/uploads/202508/33652628923188080928.jpg',
			create_time: '2025-09-05 16:09:41'
		}];
	}

	function detail(item) {
		console.log('系统信息详情', item);
		item.has_read = 1;
		pageRoute("/servePages/notice/system-view/system-view?id=" + item.id)
	}

	function pageRoute(url) {
		uni.navigateTo({
			url
		});
	}

	function pageTabRoute(url) {
		uni.reLaunch({
			url
		});
	}

	const {
		title,
		themeColor,
		imgHost,
		isMore,
		list,
		noread,
	} = toRefs(state);
</script>

<style lang="scss">
	.notice-system {}
</style>